package com.zy.web.demo.wenjian;

import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
 * @author zy
 * @version 1.0
 * @date 2021/4/13 20:12
 */
public class Demo {

    private static final String filePath = "E:\\编程\\超星\\web";

    private static List<String> list = new ArrayList<>();

    private static List<String> matchRegexList = new ArrayList<String>();

    public static void main(String[] args) {

        getFiles(filePath);
        // 给文件进行去重
        Duplicate();
    }

    public static void getFiles(String filePath)  {
        // 遍历所有文件
        File file = new File(filePath);
        File[] files = file.listFiles();
        for (File file1 : files) {
            if ( file1.isDirectory() ){
                getFiles(file1.getAbsolutePath());
            }else {
                list.add(file1.getName());
                // 读取文件
                FileInput(file1);
            }
        }
    }

    public static void FileInput(File file){

        DemoUpgrade.FileInput(matchRegexList, file);
    }

    private static void Duplicate(){
        FileOutputStream os = null;
        try {
            os = new FileOutputStream(new File("C:\\Users\\wjy\\Desktop\\文本.txt"),true);
            List<String> collect = matchRegexList.stream().distinct().collect(Collectors.toList());
            for (String s : collect) {
                os.write(s.getBytes());
                os.write("\r\n".getBytes());
            }
            os.flush();
            os.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


}
